Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@leafygreen-ui/hooks
Advanced tools
yarn add @leafygreen-ui/hooks
npm install @leafygreen-ui/hooks
Hook to subscribe to changes in a ref
const Example = () => {
[refNode, setRefNode] = useElementNode();
return <div ref={setRefNode}>I am a ref</div>;
};
Hook to create and remove eventListeners
useEventListener('click', handleClick, { enabled });
Prop | Type | Description | Default |
---|---|---|---|
type | Global Event Handler or string | Type of event to listen for. | |
eventCallback | function | Callback executed when event is triggered. | |
optional.options | AddEventListenerOptions | Parameter to specify options passed to the eventListener | |
optional.enabled | boolean | Determines whether the event handler is attached or not. | true |
optional.dependencies | Array | Array to be passed to useEffect hook, such that the hook will only run if the array's values have changed. | [enabled, type] |
optional.element | Document or HTMLElement | The DOM node to attach the event handler to. Defaults to document . | document |
Hook that listens for EscapeKey
press.
useEscapeKey(handleEscapeCallback);
Prop | Type | Description | Default |
---|---|---|---|
callback | function | Callback executed when EscapeKey is pressed. | |
optional | object | Optional argument passed to function with implementation specifications. See supported parameters for useEventHandler. |
const lastTimeContentElMutated = useMutationObserver(
target,
mutationOptions,
() => Date.now(),
adjustOnMutation,
);
Prop | Type | Description | Default |
---|---|---|---|
target | HTMLElement or null | HTMLElement to subscribe to changes to. | |
options | MutationObserverInit | Object with information about what DOM changes to subscribe to. Docs here | |
callback | function | Callback function to execute inside of MutationObserver instance. | |
enabled | boolean | Determines whether the event handler is attached or not. | true |
Hook to subscribe to changes in viewport size
const viewportSize = useViewportSize();
Hook to create a Poller that polls at a given interval.
If your onPoll
handler returns a Promise
it will wait for the Promise to resolve or reject before scheduling the next interval.
This hooks also makes use of the Page Visibility API. If the page is hidden
then polling will stop. When a page becomes visible
again then polling will resume.
usePoller(onPoll, {
interval: 30000,
immediate: true,
enabled: true,
});
Prop | Type | Description | Default |
---|---|---|---|
onPoll | function | Callback executed when poll interval occurs. | |
optional.interval | number | What interval the onPoll should be called. | 30000 |
optional.immediate | boolean | If we immediately poll, if false we wait till first interval occurs. | true |
optional.enabled | boolean | Is polling enabled. | true |
FAQs
LeafyGreen UI Kit Custom Hooks
The npm package @leafygreen-ui/hooks receives a total of 57,618 weekly downloads. As such, @leafygreen-ui/hooks popularity was classified as popular.
We found that @leafygreen-ui/hooks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.